package com.changh.controllor;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * @author jenny
 * @version V1.0  
@Description: TODO(用一句话描述该文件做什么)
 */
public class ValidateInfoServlet extends HttpServlet {

	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		doPost(req, resp);
		
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//System.out.println("doPost----------------");
		
		response.setContentType("text/html;charset=utf-8");
		String type=request.getParameter("type");
		
	
		if("login".equals(type)){
			
			validateLogin(request, response);
		}else if("getCheckCode".equals(type)){
			
			requestGetCheckCode(request, response);
		}
		
	}
	
	/**
	 * 提交验证码登录处理
	 */
	private void validateLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		
		
		String tel=request.getParameter("tel");
		String check=request.getParameter("check");
		
		System.out.println("tel=="+tel+",,,check==="+check);
		//req.getRequestDispatcher("../register_page.html").forward(req, resp);
		//resp.sendRedirect("../get_favorable.html");
		
		PrintWriter out=response.getWriter();
		//验证
		
		if((null!=tel&&tel.equals("15900000000"))&&(null!=check&&check.equals("abcd"))){
			
			System.out.println("is ok?");
			out.println("success");
		}else{
			
			out.println("failue");
		}
		
		
	}
	
	/**
	 * 提交验证码登录处理
	 */
	private void requestGetCheckCode(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		
		
		//调用获取验证码的业务逻辑
		System.out.println("获取验证码逻辑");
		
		
	}
}
